﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PluginXtraZone
{
    public static class AsciiEditing
    {
        public static string CharsToAscii(string value)
        {
            foreach (Match m in Regex.Matches(value, ("[aéàèëöüïäêûîôâ]"), RegexOptions.IgnoreCase))
            {
                string index = Convert.ToInt32(m.Value[0]).ToString();
                while (index.Length < 3)
                {
                    index = ("0" + index);
                }
                value = value.Replace(m.Value, "&#" + index + ";");
            }

            return value;
        }

        public static string AsciitoChars(string value)
        {
            foreach (Match m in Regex.Matches(value, ("&amp;#\\d\\d\\d;"), RegexOptions.IgnoreCase))
            {
                value = value.Replace(m.Value, Char.ConvertFromUtf32(Convert.ToInt32(m.Value.Remove(0, 6).Remove(3, 1))).ToString());
            }

            return value;
        }
    }
}
